shell 练习-监控节点

一个网站,使用了cdn,全国各地有几十个节点。需要你写一个shell脚本来监控各个节点是否正常。

假如

  1. 监控的url为www.yanyi.com/index.php
  2. 源站ip为88.88.88.88
  3. 以及各个节点ip列表文件为/tmp/ip.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
url="www.yanyi.com/index.php"
s_ip="88.88.88.88"
curl -x $s_ip:80 $url > /tmp/source.html 2>/dev/null
for ip in `cat /tmp/ip.txt`
do
curl -x $ip:80 $url 2>/dev/null >/tmp/$ip.html
[ -f /tmp/$ip.diff ] && rm -f /tmp/$ip.diff
touch /tmp/$ip.diff
diff /tmp/source.html /tmp/$ip.html > /tmp/$ip.diff 2>/dev/null
n=`wc -l /tmp/$ip.diff|awk '{print $1}'`
if [ $n -lt 0 ]
then
echo "node $ip sth wrong."
fi
done